package com.yb.auth.core.constant;

import com.yb.auth.core.bean.SysUserMobileAuthentication;
import com.yb.auth.core.bean.SysUserPassAuthentication;
import com.yb.core.constant.HttpConstant;
import com.yb.core.exception.YbBusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

public class LoginConstant {

    @AllArgsConstructor
    @NoArgsConstructor
    @Getter
    public enum LoginType{
        USER_PASS(0,"userPassLoginStrategy"),
        USER_MOBILE(1,"userMobileLoginStrategy");
        Integer type;
        String name;

        public static LoginType parse(Integer type){
            if(Objects.isNull(type))return USER_PASS;
            Optional<LoginType> optional = Arrays.stream(values()).filter(item -> item.type == type).findFirst();
            if(optional.isPresent()){
                return optional.get();
            }

            throw new YbBusinessException(HttpConstant.Response.LOGIN_TYPE_ERROR);
        }
    }

    @AllArgsConstructor
    @NoArgsConstructor
    @Getter
    public enum LoginTokenType{
        USER_PASS(0, SysUserPassAuthentication.class),
        USER_MOBILE(1, SysUserMobileAuthentication.class);
        Integer type;
        Class<?> clazz;

        public static Class<?> getActualClass(Integer type){
            if(Objects.isNull(type))return null;
            for (LoginTokenType loginTokenType : values()) {
                if(loginTokenType.type==type)return loginTokenType.clazz;
            }
            return null;
        }
    }
}
